package com.demo.pattern.config;

import com.demo.pattern.service.ChannelFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.ServiceLocatorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通过spring的服务定位工厂类 注入渠道工厂
 */
@Configuration
public class ChannelConfig {

    @Bean("channelFactory")
    public FactoryBean serviceLocatorFactoryBean() {
        ServiceLocatorFactoryBean factoryBean = new ServiceLocatorFactoryBean();
        factoryBean.setServiceLocatorInterface(ChannelFactory.class);
        return factoryBean;
    }

}
